﻿using System.Globalization;
using System.Windows.Data;

namespace ImageGenerator.Helpers
{
    public class String2FontFamilyConverter : IValueConverter
    {
        private readonly Dictionary<string, string> dict = new() {
            { "仓耳小丸子", "仓耳小丸子.ttf#仓耳小丸子" },
            { "猫啃什锦黑", "猫啃什锦黑.ttf#猫啃什锦黑" },
            { "庞门正道细线体", "庞门正道细线体.ttf#庞门正道细线体" },
            { "宅在家麥克筆", "#StarLoveMarker" },
            { "站酷庆科黄油体", "站酷庆科黄油体.ttf#站酷庆科黄油体" },
            { "字魂扁桃体", "字魂扁桃体.ttf#字魂扁桃体" },
        };
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var key = (string)value;
            if (!string.IsNullOrWhiteSpace(key) && dict.ContainsKey(key))
                return new System.Windows.Media.FontFamily(new Uri("pack://application:,,,/"), "./Assets/Fonts/" + dict[key]);
            else
                return new System.Windows.Media.FontFamily("黑体");
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
